@extends('layout.app') @section('content')

<div class="box-body">

    <table id="rowed3"></table>
    <div id="prowed3"></div>

</div>

<script>
    $(document).ready(function() {

        var data = {
            url: "/setting/role",
            colNames: ['Id', '角色名称', '角色权限'],
            colModel: [{
                name: 'role_id',
                index: 'role_id',
                key: true
            }, {
                name: 'name',
                editable: true
            }, {
                name: 'acl',
                sortable: false,
                search: false,
                formatter: function(cellvalue, options, object) {
                    return '<a href="javascript:;" onclick="model(' + object.role_id + ')"><i class="fa fa-link text-danger"></i> </a>';
                }
            }],
            caption: '<i class="fa fa-user"></i> 角色列表',
            editurl: "/setting/role/edit",
            sortname: 'role_id',
            sortorder: "asc",
            autowidth: false,
        };

        jqGrid(data, true, true, true);
    });

    function model(id) {

        $("input[name=id]").val(id);

        var html = $("#modal-body").html();

        console.log(html);

        $("#modal-body").html('<img src="/img/loaders/11.gif">');

        $('#aclModal').modal();

        $.ajax({
            type: "GET",
            url: "/acl/" + id,
            dataType: "json",
            success: function(data) {

                $("#modal-body").html(html);

                $("input[name=uris\\[\\]]").each(function() {
                    $(this).prop("checked", false);
                    for (index in data) {
                        if ($(this).val() == data[index]) {
                            $(this).prop("checked", true);
                        }
                    }
                })
            }
        });
    }
</script>

<div class="modal fade" id="aclModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title"><i class="fa fa-user"></i> 角色权限</h4>
            </div>
            <div class="modal-body" id="modal-body">
                <form id="aclForm" method="post" action="/acl">
                    {!! csrf_field() !!}
                    <input type="hidden" name="id" value="" />
                    <table class="table table-bordered table-condensed table-hover">
                        <thead>
                        </thead>
                        <tbody>
                        <?php $col = 4; ?> @foreach(\App\Http\Route::label() as $key => $label)
                            <tr>
                                <td colspan="4"><span class="label label-danger">{{$key}}</span></td>
                            </tr>
                            <tr>
                                <?php $i = 0;?> @foreach($label as $name => $item)
                                    <?php $i++ ?>
                                    <td width="25%" class="text-center">
                                        <input type="checkbox" name="uris[]" value="{{$item['uri']}}" />
                                        <span class="label label-info">{{$name}}</span>
                                    </td>
                                    @foreach($item['ajax'] as $ajax)
                                        <?php $i++ ?>
                                        <td width="25%" class="text-center">
                                            <input type="checkbox" name="uris[]" value="{{$ajax['uri']}}" />
                                            <span class="label label-default">{{$ajax['label']}}</span>
                                        </td>
                                        @if($i % $col == 0)
                            </tr>
                            <tr>
                                @endif @endforeach
                                <?php $m = $i % $col; if($m > 0):?> @for($j = $col ; $j > $m ; $j--)
                                    <?php $i++ ?>
                                    <td></td>
                                @endfor
                                <?php endif?>
                            </tr>
                            <tr>
                                @endforeach
                                <?php $m = $i % $col; if($m > 0):?> @for($j = $col ; $j > $m ; $j--)
                                    <td></td>
                                @endfor
                                <?php endif?>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </form>
            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-success" onclick="$('#aclForm').submit()"><i class="fa fa-save"></i> 确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->
@endsection